// pages/my/my.js
import api from '../../utils/api';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    show2: false,
    imgalist:['https://api.meetcoaching.cn/uploads/evaluation/qrcode/wechat.jpeg'],
    imgalist2:['https://api.meetcoaching.cn/uploads/evaluation/qrcode/coach.jpeg'],
    caochDetail:['https://api.meetcoaching.cn//uploads/evaluation/qrcode/coach_detail.jpeg'],
    logingState:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    let token = wx.getStorageSync('token');
    if(token!=null && token!=''){
      this.setData({
        logingState:true
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bespoke:function(){
    wx.navigateTo({
      url: '/pages/record/index',
    })
  },
  kf:function(){
    this.setData({
      show: true
    })
  },
  jd:function(){
    this.setData({
      show2: true
    })
  },

  onClose() {
    this.setData({ close: false });
  },
  newPat() {
    console.log(1111);
  },
  previewImage: function (e) {
    wx.previewImage({
    current: this.data.imgalist, // 当前显示图片的http链接
    urls: this.data.imgalist // 需要预览的图片http链接列表
    })
    },
  previewImage2: function (e) {
    wx.previewImage({
    current: this.data.caochDetail , // 当前显示图片的http链接
    urls: this.data.caochDetail // 需要预览的图片http链接列表
    })
    },
    smzc:function(e){
      wx.navigateTo({
        url: '../smzc/index',
      })
    },
    bindGetUserInfo: function (e) {
      let code = wx.getStorageSync('code');
      let scene = wx.getStorageSync('scene');
      console.log(e)
      if (e.detail.userInfo) {
          //用户按了允许授权按钮
              wx.getUserInfo({
                success: res => {
                  console.log(res)
                  //获取token
                  api.post("evaluation/openid", {
                    "code":code,
                    "encryptedData":res.encryptedData,
                    "vi":res.iv,
                    "raw_data":res.rawData,
                    "channel_id":scene
                  }).then(res => {
                    console.log(res)
                    var token = res.data.token
                    //将token存到本地存储中
                    wx.setStorageSync('token',token);
                    //授权成功后，跳转进入小程序首页
                    wx.switchTab({
                      url: '/pages/select/select',
                    })
                  }).catch(err => {
                      wx.showToast({
                          title: err.message,
                          icon: 'none'
                      })
                  })   
            }
        })
      } else {
        wx.switchTab({
          url: '/pages/my/my',
        })
      }
  },
})